const messageDuration = 3000
const msgOptions = {
  offset: 60,
  showClose: true,
  dangerouslyUseHTMLString: true,
  duration: messageDuration
}

const notifyOption = {
  position: 'top-right',
  duration: messageDuration
}

const messagebox = {
  /* 全局Message */
  $showSuccessMsg(message) {
    this.$message({ ...msgOptions, ...{ message: message, type: 'success' }})
  },
  $showWarningMsg(message) {
    this.$message({ ...msgOptions, ...{ message: message, type: 'warning' }})
  },
  $showInfoMsg(message) {
    this.$message({ ...msgOptions, ...{ message: message, type: 'info' }})
  },
  $showErrorMsg(message) {
    this.$message({ ...msgOptions, ...{ message: message, type: 'error' }})
  },
  /* 全局Notification */
  $showSuccessNotify(message) {
    this.$notify({ ...notifyOption, ...{ message: message, title: this.$t('common.msgBox.notifyTitle'), type: 'success' }})
  },
  $showWarningNotify(message) {
    this.$notify({ ...notifyOption, ...{ message: message, title: this.$t('common.msgBox.notifyTitle'), type: 'warning' }})
  },
  $showInfoNotify(message) {
    this.$notify({ ...notifyOption, ...{ message: message, title: this.$t('common.msgBox.notifyTitle'), type: 'info' }})
  },
  $showErrorNotify(message) {
    this.$notify({ ...notifyOption, ...{ message: message, title: this.$t('common.msgBox.notifyTitle'), type: 'error' }})
  },
  /* 全局Alert */
  $showAlert({ msg, ok = null }) {
    this.$alert(msg, this.$t('common.msgBox.alertTitle'), {
      confirmButtonText: this.$t('common.msgBox.ok'),
      dangerouslyUseHTMLString: true,
      callback: () => {
        if (ok) { ok() }
      }
    })
  },
  /* 全局Confirm */
  $showConfirm({ msg, ok = null, ng = null }) {
    this.$confirm(msg, this.$t('common.msgBox.confirmTitle'), {
      confirmButtonText: this.$t('common.msgBox.ok'),
      cancelButtonText: this.$t('common.msgBox.cancel'),
      closeOnClickModal: false,
      type: 'warning'
    })
      .then(() => {
        if (ok) { ok() }
      })
      .catch((action) => {
        if (ng) { ng() }
      })
  }
}

export const msgbox = {
  methods: {
    ...messagebox
  }
}
